// https://leetcode.cn/problems/online-stock-span/
// Created by ade on 2022/10/21.
//
#include <queue>
#include <vector>
#include <iostream>

using namespace std;

class StockSpanner {
public:
    // ["StockSpanner","next","next","next","next","next","next","next"]
    // [[],[100],[80],[60],[70],[60],[75],[85]]
    // 思路：单调栈 维护一个单调递减的栈
    vector<int> prices = {};
    vector<int> weights = {};

    StockSpanner() {

    }

    int next(int price) {
        if (prices.empty() || !prices.empty() && price < prices.back()) {
            prices.push_back(price);
            weights.push_back(1);
            return weights.back();
        }
        int tmp = 1;
        while (!prices.empty() && price >= prices.back()) {
            tmp += weights.back();
            prices.pop_back();
            weights.pop_back();
        }
        prices.push_back(price);
        weights.push_back(tmp);
        return weights.back();
    }
};